package com.example.event_android

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
import com.ohuang.eventbus.EventBus
import com.ohuang.eventbus.Subscribe

class MainActivity2 : AppCompatActivity() {
    var tv:TextView?=null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)
        //传入LifecycleOwner  onDestroy的时候会自动unregister
        EventBus.get().register(this,this)
        tv=findViewById(R.id.test)
        tv?.setOnClickListener {
            EventBus.get().post("你好啊")
        }
    }
    @Subscribe(sticky=true)
    fun show(s:String) {

        Toast.makeText(this,s,Toast.LENGTH_SHORT).show()
    }
}